package com.xxl.shoppingapp.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xxl.shoppingapp.R;
import com.xxl.shoppingapp.base.BaseRecyclerViewAdapter;
import com.xxl.shoppingapp.base.BaseViewHolder;
import com.xxl.shoppingapp.entity.CommonProduct;

import butterknife.Bind;

/**
 * @author xuelian.xiong 2018/4/12
 * @Package com.xxl.shoppingapp.ui.adapter
 * @Title: ProductListAdapter
 * @Description: (用一句话描述该文件做什么)
 * Copyright (c) 传化公路港物流有限公司版权所有
 * Create DateTime: 2018/4/12
 */
public class ProductListAdapter extends BaseRecyclerViewAdapter<CommonProduct> implements View.OnClickListener {
    public int getItemLayout() {
        return R.layout.item_product_listview;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), getItemLayout(), null);
        RecyclerView.ViewHolder holder = new CartListHolder(view);
        view.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CartListHolder vh = (CartListHolder) holder;
        vh.tvName.setText(getItem(position).getProductName());
        vh.itemView.setTag(position);
    }

    @Override
    public void onClick(View v) {
        if (mItemClickListener != null) {
            mItemClickListener.onItemClick((Integer) v.getTag());
        }
    }

    class CartListHolder extends BaseViewHolder {
        @Bind(R.id.iv_post)
        ImageView ivPost;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_price)
        TextView tvPrice;
        @Bind(R.id.tv_quality)
        TextView tvQuality;
        @Bind(R.id.tv_address)
        TextView tvAddress;

        public CartListHolder(View itemView) {
            super(itemView);
        }


    }
}
